// import com.alibaba.druid.sql.ast.SQLExpr;
// import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
// import com.alibaba.druid.sql.ast.statement.SQLSelectItem;
// import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitor;

// import java.util.ArrayList;
// import java.util.List;

#include "SQLServerOutput.h"
#include "../visitor/SQLServerASTVisitor.h"
#include "../../../../utils/listTran.h"
#include "../../../ast/statement/SQLSelectItem.h"
#include "../../../ast/statement/SQLExprTableSource.h"

SQLServerOutput::SQLServerOutput()
{
  columns = std::make_shared<std::list<SQLExpr_ptr>>();
  selectList = std::make_shared<std::list<SQLSelectItem_ptr>>();
}

// @Override
void SQLServerOutput::accept0(SQLServerASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLServerOutput)))
  {
    SQLObject_list_ptr tmp1 = ListTran::tran_class<SQLSelectItem, SQLObject>(selectList);
    this->acceptChild(visitor, tmp1);
    this->acceptChild(visitor, into);
    SQLObject_list_ptr tmp2 = ListTran::tran_class<SQLExpr, SQLObject>(columns);
    this->acceptChild(visitor, tmp2);
  }

  visitor->endVisit(SharedObject(SQLServerOutput));
}

SQLExprTableSource_ptr SQLServerOutput::getInto()
{
  return into;
}

void SQLServerOutput::setInto(SQLExprTableSource_ptr into)
{
  this->into = into;
}

SQLExpr_list_ptr SQLServerOutput::getColumns()
{
  return columns;
}

SQLSelectItem_list_ptr SQLServerOutput::getSelectList()
{
  return selectList;
}

SQLObject_ptr SQLServerOutput::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<SQLServerOutput>(new SQLServerOutput());
  std::shared_ptr<SQLServerOutput> x = std::dynamic_pointer_cast<SQLServerOutput>(clone_tmp);
  // SQLServerOutput x = new SQLServerOutput();
  if (into != nullptr)
  {
    x->setInto(std::dynamic_pointer_cast<SQLExprTableSource>(into->clone()));
  }
  for (SQLExpr_ptr c : *columns)
  {
    SQLExpr_ptr c2 = std::dynamic_pointer_cast<SQLExpr>(c->clone());
    c2->setParent(x);
    x->columns->push_back(c2);
  }
  for (SQLSelectItem_ptr item : *selectList)
  {
    SQLSelectItem_ptr item2 = std::dynamic_pointer_cast<SQLSelectItem>(item->clone());
    item2->setParent(x);
    x->selectList->push_back(item2);
  }
  return x;
}
